class Counter(object):
    def __init__(self, n = 8):
        self.n = n
        self.A = [0] * n
        self.m = 0
    def inc(self):
        i = 0
        while i < self.n and self.A[i] == 1:
            self.A[i] = 0
            i += 1
        if i < self.n:
            self.A[i] = 1
            if i > self.m:
                self.m = i
        else:
            self.m = 0
    def reset(self):
        for i in xrange(self.m):
            self.A[i] = 0
        self.m = 0
    def __str__(self):
        return str(self.A[:self.m + 1])
        
if __name__ == '__main__':
    a = Counter()
    for j in xrange(10):
        a.inc()
        print 'after inc:', a
    a.reset()
    print 'after reset:', a